<?php
include_once "../lib/DAL/LapLich.php";
class LapLichBLL{
    function __construct(){
        
    }
    
    function __destruct(){
        
    }
    
    public function setLapLichBLL($row){
        $laplich = new LapLich();
        $laplich->setLapLich($row['ma_lopmon'],$row['ma_cb'],$row['nguoiduyet'],$row['nhomlich_laplich'],$row['khoahoc_lop']);
        return $laplich;         
    }
    public function InsertLaplichBLL($laplich)
    {
        $sql="INSERT INTO   tbl_laplich(ma_lopmon,ma_cb,nguoiduyet,nhomlich_laplich,khoahoc_lop) 
                                VALUES ('".$laplich->getma_lopmon()."',
                                        '".$laplich->getma_cb()."',
                                        '".$laplich->getnguoiduyet()."',
                                        '".$laplich->getnhomlich_laplich()."',
                                        '".$laplich->getkhoahoc_lop()."')";
        
        $ex=mysql_query($sql);
        return $ex;
    }
    public function DuyetLich($ma_cb,$malich){
        $sql="UPDATE tbl_laplich SET nguoiduyet='$ma_cb' WHERE nhomlich_laplich='$malich'";
        $ex=mysql_query($sql);
        
        $sql_lopmon="SELECT ma_lopmon FROM tbl_laplich WHERE nhomlich_laplich='$malich'";
        $ex_lopmon=mysql_query($sql_lopmon);
        $ngay=date('d/m/Y');
        if($ex_lopmon){
            while($row=mysql_fetch_array($ex_lopmon)){
                $ma_lopmon=$row['ma_lopmon'];
                mysql_query("UPDATE tbl_lopmon SET trangthai_hientai='daduyet' WHERE ma_lopmon='$ma_lopmon'");
                $ma_qtlm=$ma_lopmon."-daduyet";
                mysql_query("INSERT INTO tbl_quatrinhlopmon(ma_qtlm,noidungthuchien,thoigianthuchien,ma_cb,ma_lopmon,madm_ttlm) 
                                                    VALUES ('$ma_qtlm','Duyệt mở lớp','$ngay','$ma_cb','$ma_lopmon','daduyet')");
                }
        }
        
        
        
        return $ex;
    }
    
    public function get_CanBoLap($lich){
        $sql="SELECT DISTINCT tbl_laplich.ma_cb,ma_hochamhocvi,hoten_cb FROM tbl_laplich,tbl_canbo WHERE tbl_laplich.ma_cb=tbl_canbo.ma_cb AND nhomlich_laplich='$lich'";
        $kq= mysql_fetch_array(mysql_query($sql));
        $mangkq['ma_cb']=$kq['ma_cb'];
        $mangkq['hh_hoten_cb']=$kq['ma_hochamhocvi'].".".$kq['hoten_cb'];
        return $mangkq;
    }
    
    public function get_CanBoDuyet($lich){
        $sql="SELECT DISTINCT ma_hochamhocvi,hoten_cb FROM tbl_laplich,tbl_canbo WHERE tbl_laplich.nguoiduyet=tbl_canbo.ma_cb AND nhomlich_laplich='$lich'";
        $ex=mysql_query($sql);
        if(mysql_num_rows($ex)>0){
            $kq= mysql_fetch_array($ex);        
            return $kq['ma_hochamhocvi'].".".$kq['hoten_cb'];
        }else{
            return null;
        }
            
    }
}

?>